package net.linku.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import net.linku.annotation.AutoResponse;
import net.linku.model.req.privilege.AdminStatusChangeReq;
import net.linku.model.req.role.AdminRoleReq;
import net.linku.model.req.role.AdminRoleReqQuery;
import net.linku.model.resp.login.LARoleVO;
import net.linku.service.LARoleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 后台角色管理控制器
 */
@RestController
@AutoResponse
@RequiredArgsConstructor
@RequestMapping("/roles")
@Api(tags = "后台角色管理控制器")
public class AdminRoleController {

    private final LARoleService roleService;

    @PostMapping("/list")
    @ApiOperation(value = "分页查询角色列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "query", value = "查询条件", required = true, dataType = "AdminRoleReqQuery", paramType = "body")
    })
    public Page<LARoleVO> pageRoles(@Validated @ApiIgnore @RequestBody AdminRoleReqQuery query) {
        return roleService.pageRoles(query);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleReq", value = "角色请求对象", required = true, dataType = "AdminRoleReq", paramType = "body")
    })
    public Boolean addRole(@RequestBody @Validated AdminRoleReq roleReq) {
        return roleService.addRole(roleReq);
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleReq", value = "角色请求对象", required = true, dataType = "AdminRoleReq", paramType = "body")
    })
    public Boolean updateRole(@RequestBody @Validated AdminRoleReq roleReq) {
        return roleService.updateRole(roleReq);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "statusChangeReq", value = "角色状态变更请求对象", required = true, dataType = "AdminRoleStatusChangeReq", paramType = "body")
    })
    public Boolean deleteRole(@RequestBody @Validated AdminStatusChangeReq statusChangeReq) {
        return roleService.deleteRole(statusChangeReq);
    }
}
